package com.credithc.signature.manager.ro;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Data
@Slf4j
public class ChannelRo {

    private Integer companyId;

    private String code;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", locale = "zh")
    private Date createTime;

    private List<String> channelIds;

    private Integer pageSize;

    private Integer pageNo;

    private Date createTimeS;

    private Date createTimeE;

    private String timeRange;


    public void setTimeRange(String timeRange) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        this.timeRange = timeRange;
        if (StringUtils.isNotBlank(timeRange)) {
            try {
                String[] split = timeRange.split(" - ");
                this.createTimeS = simpleDateFormat.parse(split[0]);
                this.createTimeE = simpleDateFormat.parse(split[1]);
            } catch (ParseException e) {
                log.error("处理ChannelRo.timeRange字段时发生异常", e);
            }
        }
    }

//    public void setEffectiveTimeRange(String effectiveTimeRange) {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        this.timeRange = timeRange;
//        if (StringUtils.isNotBlank(timeRange)) {
//            try {
//                String[] split = timeRange.split(" - ");
//                this.effectiveTimeS = simpleDateFormat.parse(split[0]);
//                this.effectiveTimeE = simpleDateFormat.parse(split[1]);
//            } catch (ParseException e) {
//                log.error("处理ChannelRo.timeRange字段时发生异常", e);
//            }
//        }
//    }
}
